<?php
session_start();
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../../value/value_vn.php";
		}
		else {
			$value = "../../value/value_kr.php";
		}
		return $value;
	}
include '../../operations/connection.php';	
$value = getlang();
include($value);
$page=$_GET['page'];
$action=$_GET['action'];
	
$rows_per_page = 5 ;
$page_start = ( $page - 1 ) * $rows_per_page; 
$page_end = $page * $rows_per_page;
$id_employee=$_SESSION['IDEmployee'];
if($action=="not_app") {
	$sql="SELECT a.SumMoney,a.IDApproveDoc,e.FullName,e.IDEmployee,a.Tile,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,a.IDTypeDoc,b.isView,a.IDStatus FROM approvedoc a INNER JOIN listapprove b
		ON a.IDGroupApprove = b.IDGroupApprove INNER JOIN employee e ON a.IDEmployee = e.IDEmployee
		WHERE CONVERT(b.IDEmployee USING UTF8) = CONVERT( '$id_employee' USING UTF8)
		AND CONVERT(a.IDTypeDoc USING UTF8) != 11
		AND CONVERT(a.IDStatus USING UTF8) = 2
		AND CONVERT(b.IDStatus USING UTF8) = 2 Order by a.Timecreate";
$queryNotApp  = mysql_query($sql);
$number_of_page_not_app = ceil ( mysql_num_rows( $queryNotApp ) / $rows_per_page ); 
?>
<table cellpadding="5" cellspacing="0" class="rf_dt" >
                    <tr  class="table_new">
                    <td width="3%"><?=$l_no?></td>
                    <!--td width="10%">ID</td-->
                    <td width="20%"><?=$l_document_form?></td>
                    <td width="34%"><?=$l_title?></td>
                    <td width="12%"><?=$l_writer?></td>
                    <td width="12%"><?=$l_created_date?></td>
                    <td width="12%"><?=$l_status?></td>
                    </tr>
                    <?php									
											    $i = 0; 
											    while ($row=mysql_fetch_array($queryNotApp)){
											    	if ( $i >= $page_start  ) 
													{ 
												    	if($row[IDTypeDoc]==7)$document = $l_vacation_form;
												    	else if($row[IDTypeDoc]==12)$document = $l_assignment_report;
												    	else if($row[IDTypeDoc]==13)$document = $l_purchase_order;
												    	else if($row[IDTypeDoc]==14)$document = $l_daily_report;
												    	else if($row[IDTypeDoc]==15)$document = $l_business_trip_report;
												    	else if($row[IDTypeDoc]==16)$document = $l_weekly_report;
												    	else if($row[IDTypeDoc]==17)$document = $l_susqence_payment_request;
												    
												?>
													<tr bgcolor="#ffffff" class="highlighter">
														<td width="3%" align="center"><?=($i+1)?></td>
														<!--td  align="center"><a href="received.php?id=<?=$row[IDApproveDoc]?>&type= <?=$row[IDTypeDoc]?>"><?php echo $row[IDApproveDoc];?></a></td-->
														<td  align="left"><div  align="left" ><?php echo $document;?></div></td>
														<td  align="left">
															<div  align="left" >
																<a href="received.php?id=<?=$row[IDApproveDoc]?>&type= <?=$row[IDTypeDoc]?>"><?=$row[Tile]?> </a>
																
																
																<?php if ($row[isView]==0){
																	echo "<span style='font-size:10px;'><span style='color: rgb(0, 0, 255); '><em>  [".$l_new."]</em></span></span>";
																}
																?>
															<p style="float:right">
															<?php 
																if($row[IDTypeDoc]==13 || $row[IDTypeDoc]==15 || $row[IDTypeDoc]==17){
																	if($row[SumMoney]>0){
																		echo " [ ".number_format($row[SumMoney])." ]";
																	}else{
																		if($row[IDTypeDoc]==15 || $row[IDTypeDoc]==13){
																			$s1="select sum(buying_document.total) as tongtien from approvedoc,buying_document where approvedoc.IDApproveDoc=buying_document.document_id and approvedoc.IDApproveDoc='".$row[IDApproveDoc]."' GROUP BY approvedoc.IDApproveDoc";
																			$k1=mysql_query($s1);
																			while ($r1=mysql_fetch_array($k1)){
																				if($r1[tongtien]>0){
																					echo " [ ".number_format($r1[tongtien])." ]";
																				}
																			}
																		}else if($row[IDTypeDoc]==17){
																			$s1="select sum(ap_advance.money) as tongtien from approvedoc,ap_advance where approvedoc.IDApproveDoc=ap_advance.document_id and approvedoc.IDApproveDoc='".$row[IDApproveDoc]."' GROUP BY approvedoc.IDApproveDoc";
																			$k1=mysql_query($s1);
																			while ($r1=mysql_fetch_array($k1)){
																				if($r1[tongtien]>0){
																					echo " [ ".number_format($r1[tongtien])." ]";
																				}
																			}
																		}
																	}
																}
															?>
															</p>
															</div>
														</td>
														<td align="center" ><?=$row[FullName]?></td>
														<td align="center"><?=$row[Timecreate]?></td>
														<!--  >td !><?=$row[IDStatus]?></td-->
														<td align="center" ><?=$l_status_pending?></td>
														
													</tr>
												<?php 	}
												
													$i++; 
													
													if ($i >= $page_end) 
													{ 
													break; 
													} 
												}
												
													
												?>
                    <tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="6">
                        	<div style="text-align: center; width: 100%">
                            	<span class="rf-ds">
														
														<?php if ( $number_of_page_not_app > 1 ) 
														{ 
															if ($page==1)
																$p=2;
															else if ($page==$number_of_page_not_app)
																$p=$number_of_page_not_app-1;
															else $p=$page;
															if($page!=1){?>
																<a onclick="paging(1,'not_app')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																<a onclick="paging(<?=($page-1)?>,'not_app')" ><span class='button_next' ><?php echo "<<";?></span> </a>
															<?php  }
															else{
																echo "<span class='button_next'><<<</span>"; 
																echo "<span class='button_next'><<</span>";
															}
															for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																	if ($i<=$number_of_page_not_app && $i>0)
																	
																		if ($i==$page){
																			echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																		}else{
																		?>
																			<a onclick="paging(<?=$i?>,'not_app')" ><span class="button_next">
																			<?php 
																			echo $i;
																			?>
																			</span> </a>
																		<?php 
																		}
																	?>
																
															<?php 
																	}
																
																if($page!=$number_of_page_not_app){ ?>
																	<a onclick="paging(<?=($page+1)?>,'not_app')"><span class='button_next'><?php echo ">>";?></span> </a>
																	<a onclick="paging(<?=($number_of_page_not_app)?>,'not_app')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																<?php }
																else{
																	echo "<span class='button_next'>>></span> ";
																	echo "<span class='button_next'>>>></span> ";
																}
															}
														
															
															?>
																												
													</span>
													</div>
													</td>
                    </tr>                    
                </table>
<?php 
}else if($action=="my_saved"){
$sql="SELECT a.SumMoney,a.IDApproveDoc,e.FullName,a.Tile,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,a.IDTypeDoc,a.IDStatus
								FROM approvedoc a,employee e 
								WHERE a.IDEmployee=e.IDEmployee AND a.IDEmployee='$id_employee' AND a.IDStatus=4 Order by a.Timecreate";
$queryMySaved= mysql_query($sql);
    	
$number_of_page_my_saved = ceil ( mysql_num_rows( $queryMySaved ) / $rows_per_page ); 
	?>
	<table cellpadding="5" cellspacing="0" class="rf_dt">
                    <tr  class="table_new">
                    <td width="3%"><?=$l_no?></td>
                    <!--td width="10%">ID</td-->
                    <td width="20%"><?=$l_document_form?></td>
                    <td width="40%"><?=$l_title?></td>
                    <td width="15%"><?=$l_created_date?></td>
                    <td width="15%"><?=$l_status?></td>
                    </tr>
                    <tr>
                   <?php
												
											    $i = 0; 
											    while ($row=mysql_fetch_array($queryMySaved)){
											    	if ( $i >= $page_start  ) 
													{	
												    	if($row[IDTypeDoc]==7)$document = $l_vacation_form;
												    	else if($row[IDTypeDoc]==11)$document = $l_meeting_document;
													    else if($row[IDTypeDoc]==12)$document = $l_assignment_report;
													    else if($row[IDTypeDoc]==13)$document = $l_purchase_order;
													    else if($row[IDTypeDoc]==14)$document = $l_daily_report;
													    else if($row[IDTypeDoc]==15)$document = $l_business_trip_report;
													    else if($row[IDTypeDoc]==16)$document = $l_weekly_report;
													    else if($row[IDTypeDoc]==17)$document = $l_susqence_payment_request;
												    
												?>
													<tr bgcolor="#ffffff" class="highlighter">
														<td width="3%" align="center"><?=($i+1)?></td>
														<!--td align="center"><a href='newform.php?idapprovedoc=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>&action=editform'><?php echo $row[IDApproveDoc];?></a></td-->
														<td ><div  align="left" ><?php echo $document;?></div></td>
														<td ><div  align="left" ><a href='newform.php?idapprovedoc=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>&action=editform'><?=$row[Tile]?></a>
														<p style="float:right">
															<?php 
																if($row[IDTypeDoc]==13 || $row[IDTypeDoc]==15 || $row[IDTypeDoc]==17){
																	if($row[SumMoney]>0){
																		echo " [ ".number_format($row[SumMoney])." ]";
																	}else{
																		if($row[IDTypeDoc]==15 || $row[IDTypeDoc]==13){
																			$s1="select sum(buying_document.total) as tongtien from approvedoc,buying_document where approvedoc.IDApproveDoc=buying_document.document_id and approvedoc.IDApproveDoc='".$row[IDApproveDoc]."' GROUP BY approvedoc.IDApproveDoc";
																			$k1=mysql_query($s1);
																			while ($r1=mysql_fetch_array($k1)){
																				if($r1[tongtien]>0){
																					echo " [ ".number_format($r1[tongtien])." ]";
																				}
																			}
																		}else if($row[IDTypeDoc]==17){
																			$s1="select sum(ap_advance.money) as tongtien from approvedoc,ap_advance where approvedoc.IDApproveDoc=ap_advance.document_id and approvedoc.IDApproveDoc='".$row[IDApproveDoc]."' GROUP BY approvedoc.IDApproveDoc";
																			$k1=mysql_query($s1);
																			while ($r1=mysql_fetch_array($k1)){
																				if($r1[tongtien]>0){
																					echo " [ ".number_format($r1[tongtien])." ]";
																				}
																			}
																		}
																	}
																}
															?>
															</p>
														
														</div></td>
														<td align="center"><?=$row[Timecreate]?></td>
														<!-- >td ><?=$row[IDStatus]?></td-->
														<td align="center" ><?=$l_status_saved?></td>
														
													</tr>
												<?php 	}
												
													$i++; 
													
													if ($i >= $page_end) 
													{ 
													break; 
													} 
												}
												
													
												?>
											
											<tr>
                    <tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="6">
                        	<div style="text-align: center; width: 100%">
                            	<span class="rf-ds">
														
														<?php if ( $number_of_page_my_saved > 1 ) 
														{ 
															if ($page==1)
																$p=2;
															else if ($page==$number_of_page_my_saved)
																$p=$number_of_page_my_saved-1;
															else $p=$page;
															if($page!=1){?>
																<a onclick="paging(1,'my_saved')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																<a onclick="paging(<?=($page-1)?>,'my_saved')" ><span class='button_next'><?php echo "<<";?></span> </a>
															<?php  }
															else{
																echo "<span class='button_next'><<<</span>"; 
																echo "<span class='button_next'><<</span>";
															}
															for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																	if ($i<=$number_of_page_my_saved && $i>0)
																	
																		if ($i==$page){
																			echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																		}else{
																		?>
																			<a onclick="paging(<?=$i?>,'my_saved')" ><span class="button_next">
																			<?php 
																			echo $i;
																			?>
																			</span> </a>
																		<?php 
																		}
																	?>
																
															<?php 
																	}
																
																if($page!=$number_of_page_my_saved){ ?>
																	<a onclick="paging(<?=($page+1)?>,'my_saved')"><span class='button_next'><?php echo ">>";?></span> </a>
																	<a onclick="paging(<?=($number_of_page_my_saved)?>,'my_saved')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																<?php }
																else{
																	echo "<span class='button_next'>>></span> ";
																	echo "<span class='button_next'>>>></span> ";
																}
															}
														
															
															?>
																												
													</span>
													</div>
													</td>
                    </tr>                        
                </table>
	
	<?php 
}else if($action=="meeting_pending"){
	$sql="SELECT a.IDApproveDoc,e.FullName,a.Tile,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,a.IDTypeDoc,b.isView  
				FROM approvedoc a INNER JOIN listapprove b ON a.IDGroupApprove = b.IDGroupApprove
				INNER JOIN employee e ON a.IDEmployee = e.IDEmployee
				WHERE CONVERT(b.IDEmployee USING UTF8) = CONVERT('$id_employee'  USING UTF8)
				AND CONVERT(a.IDTypeDoc USING UTF8) = 11
				AND CONVERT(a.IDStatus USING UTF8) = 2
				AND CONVERT(b.IDStatus USING UTF8) = 2  Order by a.Timecreate";
$query_meeting_pending  = mysql_query($sql);
$number_of_page_meeting_pending = ceil ( mysql_num_rows( $query_meeting_pending ) / $rows_per_page ); 


	?>
	
	<table cellpadding="5" cellspacing="0" class="rf_dt">
                    <tr  class="table_new">
                    <td width="3%"><?=$l_no?></td>
                    <!--td width="10%">ID</td-->
                    <td width="20%"><?=$l_document_form?></td>
                    <td width="40%"><?=$l_title?></td>
                    <td width="15%"><?=$l_writer?></td>
                    <td width="15%"><?=$l_created_date?></td>
                    </tr>
                    <?php
												
											    $i = 0; 
											    while ($row=mysql_fetch_array($query_meeting_pending)){
											    	
											    	if ( $i >= $page_start  ) 
													{	
														
												    	if($row[IDTypeDoc]==7)$document = $l_vacation_form;
												    	else if($row[IDTypeDoc]==11)$document = $l_meeting_document;
													    else if($row[IDTypeDoc]==12)$document = $l_assignment_report;
													    else if($row[IDTypeDoc]==13)$document = $l_purchase_order;
													    else if($row[IDTypeDoc]==14)$document = $l_daily_report;
													    else if($row[IDTypeDoc]==15)$document = $l_business_trip_report;
													    else if($row[IDTypeDoc]==16)$document = $l_weekly_report;
													    else if($row[IDTypeDoc]==17)$document = $l_susqence_payment_request;
												    
												?>
													<tr bgcolor="#ffffff" class="highlighter">
														<td width="3%" align="center"><?=($i+1)?></td>
														<!--td align="center" ><a href='received.php?id=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>'><?php echo $row[IDApproveDoc];?></a></td-->
														<td ><div  align="left" ><?php echo $document;?></div></td>
														<td  >
															<div  align="left" >
																<a href='received.php?id=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>'><?=$row[Tile]?></a>
																<?php if ($row[isView]==0){
																	echo "<span style='font-size:10px;'><span style='color: rgb(0, 0, 255); '><em>  [".$l_new."]</em></span></span>";
																}
																?>
															</div>
														</td>
														<td align="center"><?=$row[FullName]?></td>
														<td align="center"><?=$row[Timecreate]?></td>
														
													</tr>
												<?php 	}
												
													$i++; 
													
													if ($i >= $page_end) 
													{ 
													break; 
													} 
												}
												
													
												?>
                    <tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="6">
                        	<div style="text-align: center; width: 100%">
                            	<span class="rf-ds">
														
														<?php if ( $number_of_page_meeting_pending > 1 ) 
														{ 
															if ($page==1)
																$p=2;
															else if ($page==$number_of_page_meeting_pending)
																$p=$number_of_page_meeting_pending-1;
															else $p=$page;
															if($page!=1){?>
																<a onclick="paging(1,'meeting_pending')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																<a onclick="paging(<?=($page-1)?>,'meeting_pending')" ><span class='button_next'><?php echo "<<";?></span> </a>
															<?php  }
															else{
																echo "<span class='button_next'><<<</span>"; 
																echo "<span class='button_next'><<</span>";
															}
															for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																	if ($i<=$number_of_page_meeting_pending && $i>0)
																	
																		if ($i==$page){
																			echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																		}else{
																		?>
																			<a onclick="paging(<?=$i?>,'meeting_pending')" ><span class="button_next">
																			<?php 
																			echo $i;
																			?>
																			</span> </a>
																		<?php 
																		}
																	?>
																
															<?php 
																	}
																
																if($page!=$number_of_page_meeting_pending){ ?>
																	<a onclick="paging(<?=($page+1)?>,'meeting_pending')"><span class='button_next'><?php echo ">>";?></span> </a>
																	<a onclick="paging(<?=($number_of_page_meeting_pending)?>,'meeting_pending')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																<?php }
																else{
																	echo "<span class='button_next'>>></span> ";
																	echo "<span class='button_next'>>>></span> ";
																}
															}
														
															
															?>
																												
													</span>
													</div>
													</td>
                    </tr>                           
                </table>
	<?php 
}else if($action=="meeting_sending"){
	
	$sql="SELECT a.IDApproveDoc,e.FullName,a.Tile,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,a.IDTypeDoc,DATE_FORMAT(a.TimeApprove, '%Y-%m-%d') as DateApprove  
								FROM approvedoc a,employee e 
								WHERE a.IDEmployee=e.IDEmployee AND a.IDEmployee='$id_employee' AND a.IDStatus=2 AND a.IDTypeDoc = 11 Order by a.Timecreate";
$query_meeting_sending= mysql_query($sql);
$number_of_page_meeting_sending = ceil ( mysql_num_rows( $query_meeting_sending ) / $rows_per_page ); 
	?>
		<table cellpadding="5" cellspacing="0" class="rf_dt">
                    <tr  class="table_new">
                    <td width="3%"><?=$l_no?></td>
                    <!--td width="10%">ID</td-->
                    <td width="20%"><?=$l_document_form?></td>
                    <td width="55%"><?=$l_title?></td>
                    <td width="15%"><?=$l_created_date?></td>
                    </tr>
                    <?php
												
											    $i = 0; 
											    while ($row=mysql_fetch_array($query_meeting_sending)){
											    	if ( $i >= $page_start  ) 
													{	
												    	if($row[IDTypeDoc]==11)$document = $l_meeting_document;
													    
												    
												?>
													<tr bgcolor="#ffffff" class="highlighter">
														<td width="3%" align="center"><?=($i+1)?></td>
														<!--td align="center"><a href='mydocument.php?id=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>'><?php echo $row[IDApproveDoc];?></a></td-->
														<td ><div  align="left" ><?php echo $document;?></div></td>
														<td ><div  align="left" ><a href='mydocument.php?id=<?=$row[IDApproveDoc]?>&type=<?=$row[IDTypeDoc]?>&action=my_meeting_sending'><?=$row[Tile]?></a></div></td>
														<td align="center"><?=$row[Timecreate]?></td>
														
														
													</tr>
												<?php 	}
												
													$i++; 
													
													if ($i >= $page_end) 
													{ 
													break; 
													} 
												}
												
													
												?>
                    
                    <tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="6">
                        	<div style="text-align: center; width: 100%">
                            	<span class="rf-ds">
														
														<?php if ( $number_of_page_meeting_sending > 1 ) 
														{ 
															if ($page==1)
																$p=2;
															else if ($page==$number_of_page_meeting_sending)
																$p=$number_of_page_meeting_sending-1;
															else $p=$page;
															if($page!=1){?>
																<a onclick="paging(1,'meeting_sending')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																<a onclick="paging(<?=($page-1)?>,'meeting_sending')" ><span class='button_next'><?php echo "<<";?></span> </a>
															<?php  }
															else{
																echo "<span class='button_next'><<<</span>"; 
																echo "<span class='button_next'><<</span>";
															}
															for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																	if ($i<=$number_of_page_meeting_sending && $i>0)
																	
																		if ($i==$page){
																			echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																		}else{
																		?>
																			<a onclick="paging(<?=$i?>,'meeting_sending')" ><span class="button_next">
																			<?php 
																			echo $i;
																			?>
																			</span> </a>
																		<?php 
																		}
																	?>
																
															<?php 
																	}
																
																if($page!=$number_of_page_meeting_sending){ ?>
																	<a onclick="paging(<?=($page+1)?>,'meeting_sending')"><span class='button_next'><?php echo ">>";?></span> </a>
																	<a onclick="paging(<?=($number_of_page_meeting_sending)?>,'meeting_sending')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																<?php }
																else{
																	echo "<span class='button_next'>>></span> ";
																	echo "<span class='button_next'>>>></span> ";
																}
															}
														
															
															?>
																												
													</span>
													</div>
													</td>
                    </tr>                       
                </table>
	<?php 
}
?>



<?php mysql_close($connection);?>